package com.zboin.common.domain;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * @author zhboom
 * @date 2025/5/10 11:42
 */
@Data
public class PageResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 202308202058L;

    private Integer code;

    private List<T> rows;

    private Long total;

    private String msg;

    public PageResult() {
    }

    public PageResult(Integer code, String msg, List<T> rows, Long total) {
        this.code = code;
        this.rows = rows;
        this.total = total;
        this.msg = msg;
    }

    public static <T> PageResult<T> success(List<T> rows, Long total) {
        return new PageResult<>(HttpStatus.OK.value(), "查询数据成功", rows, total);
    }


    public static <T> PageResult<T> error(List<T> rows, Long total) {
        return new PageResult<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "查询数据失败", rows, total);
    }
}
